Skip to content

Conversation

@c8ef
Copy link
Contributor

@c8ef c8ef commented Dec 17, 2025

This patch adds the IN6_IS_ADDR_MC* macro, which checks whether an address is multicast node-local address, multicast link-local address, multicast site-local address, multicast organization-local address and multicast global address.

@c8ef c8ef marked this pull request as ready for review December 17, 2025 12:33
Copy link
Contributor Author

c8ef commented Dec 17, 2025

@llvmbot
Copy link
Member

llvmbot commented Dec 17, 2025

@llvm/pr-subscribers-libc

Author: Connector Switch (c8ef)

Changes

Full diff: https://github.com/llvm/llvm-project/pull/172643.diff

2 Files Affected:

  • (modified) libc/include/llvm-libc-macros/netinet-in-macros.h (+20)
  • (modified) libc/test/include/netinet_in_test.cpp (+14)
diff --git a/libc/include/llvm-libc-macros/netinet-in-macros.h b/libc/include/llvm-libc-macros/netinet-in-macros.h
index 863ff8759e446..88ffe92756b16 100644
--- a/libc/include/llvm-libc-macros/netinet-in-macros.h
+++ b/libc/include/llvm-libc-macros/netinet-in-macros.h
@@ -64,4 +64,24 @@
   ((__LLVM_LIBC_CAST(reinterpret_cast, uint8_t *, a)[0]) == 0xfe &&            \
    (__LLVM_LIBC_CAST(reinterpret_cast, uint8_t *, a)[1] & 0xc0) == 0xc0)
 
+#define IN6_IS_ADDR_MC_NODELOCAL(a)                                            \
+  (IN6_IS_ADDR_MULTICAST(a) &&                                                 \
+   (__LLVM_LIBC_CAST(reinterpret_cast, uint8_t *, a)[1] & 0xf) == 0x1)
+
+#define IN6_IS_ADDR_MC_LINKLOCAL(a)                                            \
+  (IN6_IS_ADDR_MULTICAST(a) &&                                                 \
+   (__LLVM_LIBC_CAST(reinterpret_cast, uint8_t *, a)[1] & 0xf) == 0x2)
+
+#define IN6_IS_ADDR_MC_SITELOCAL(a)                                            \
+  (IN6_IS_ADDR_MULTICAST(a) &&                                                 \
+   (__LLVM_LIBC_CAST(reinterpret_cast, uint8_t *, a)[1] & 0xf) == 0x5)
+
+#define IN6_IS_ADDR_MC_ORGLOCAL(a)                                             \
+  (IN6_IS_ADDR_MULTICAST(a) &&                                                 \
+   (__LLVM_LIBC_CAST(reinterpret_cast, uint8_t *, a)[1] & 0xf) == 0x8)
+
+#define IN6_IS_ADDR_MC_GLOBAL(a)                                               \
+  (IN6_IS_ADDR_MULTICAST(a) &&                                                 \
+   (__LLVM_LIBC_CAST(reinterpret_cast, uint8_t *, a)[1] & 0xf) == 0xe)
+
 #endif // LLVM_LIBC_MACROS_NETINET_IN_MACROS_H
diff --git a/libc/test/include/netinet_in_test.cpp b/libc/test/include/netinet_in_test.cpp
index e8cb8e48ff4b4..72500c4d51438 100644
--- a/libc/test/include/netinet_in_test.cpp
+++ b/libc/test/include/netinet_in_test.cpp
@@ -42,4 +42,18 @@ TEST(LlvmLibcNetinetInTest, IN6Macro) {
   buff[0] = 0xff;
   buff[1] = 0x80;
   EXPECT_FALSE(IN6_IS_ADDR_SITELOCAL(buff));
+
+  buff[0] = 0xff;
+  buff[1] = 0x1;
+  EXPECT_TRUE(IN6_IS_ADDR_MC_NODELOCAL(buff));
+  buff[1] = 0x2;
+  EXPECT_TRUE(IN6_IS_ADDR_MC_LINKLOCAL(buff));
+  buff[1] = 0x5;
+  EXPECT_TRUE(IN6_IS_ADDR_MC_SITELOCAL(buff));
+  buff[1] = 0x8;
+  EXPECT_TRUE(IN6_IS_ADDR_MC_ORGLOCAL(buff));
+  buff[1] = 0xe;
+  EXPECT_TRUE(IN6_IS_ADDR_MC_GLOBAL(buff));
+  buff[1] = 0;
+  buff[0] = 0;
 }

Copy link
Contributor Author

c8ef commented Dec 18, 2025

Merge activity

  • Dec 18, 3:02 PM UTC: A user started a stack merge that includes this pull request via Graphite.

Base automatically changed from users/c8ef/12-16-_libc_add_in6_is_addr_multicast_ to main December 18, 2025 15:10
@c8ef c8ef merged commit 12d4889 into main Dec 18, 2025
14 checks passed
@c8ef c8ef deleted the users/c8ef/12-17-_libc_add_in6_is_addr_mc_ branch December 18, 2025 15:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants